function sob = sobel(bild)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Wendet auf das Bild den Sobel Kanten-Detektor an
%
%   EINGABE
%   bild... Das Bild, auf dem der Sobel Kanten-Detektor angewendet werden 
%       soll. Es soll ein Graustufen-Bild sein.
%   AUSGABE
%   sob... Das Kantenbild des Eingabebildes 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

sob = bild;
d = double(sob);

for i = 1:size(d,1)-2
    
    for j = 1:size(d,2)-2
        
        %Sobel Maske in x-Richtung
        Gx = (d(i+2,j)+2*d(i+2,j+1)+d(i+2,j+2)-d(i,j)-2*d(i,j+1)-d(i,j+2))/4;
        %Sobel Maske in y-Richtung
        Gy = (d(i,j+2)+2*d(i+1,j+2)+d(i+2,j+2)-d(i,j)-2*d(i+1,j)-d(i+2,j))/4;
       
        %Gradient
        sob(i,j) = sqrt(Gx.^2+Gy.^2);
       
    end
    
end

%Schwellenwert definieren
sob = sob > 20;

%for i = 1:size(sob,1)
    
%    for j = 1:size(sob,2)
        
%        if sob(i,j) < schwelle
%            sob(i,j) = 0;
%        else
%            sob(i,j) = 255;
%        end
%    end
%end
% sob = bwmorph(sob, 'thin');
% %sob = thinning(sob);
% %sob = uint8(sob);
% imshow(sob)

end